package org.cbg.panel;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;

import org.cbg.bean.SearchOrderBean;
import org.cbg.btn.TrslationBtn;
import org.cbg.frame.TrslationMainJframe;
import org.cbg.until.TraslationTableMyorderUntil;
import org.come.Frame.ZhuFrame;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.GsonUtil;

import com.tool.role.RoleData;
import com.tool.tcpimg.UIUtils;



/**
 * 我的藏宝阁 我的订单面板
 * 
 * @author Administrator
 * 
 */
public class TraslationMyMainMyorderJpanel extends JLayeredPane {


    private JLabel chooseLeft, yema;// ,upSort , downSort,chooseRight ,
    // 实例化下拉列表框
    private TraslationSelectOptionJpanel chooseLeftModel;// , chooseRightModel
    // 选项下拉监听标志(下拉0，没下拉1) 排序标识（0默认排序 1升序 2降序）
    private int leftFlag = 1;// ,showOrder = 0，rightFlag = 1

    /**
     * 页码按钮，首页，末页 , 左箭头, 右箭头
     */
    private TrslationBtn shouye, moye, leftArrows, rightArrows, chooseLeftArrows;

    private JScrollPane jScrollPane;

    /**
     * 当前页数 最大页码
     */
    private int dangqianyeshu = 1, zuidayema = 50;

    /**
     * 左边下拉框选取的行数 ， 右边下拉框选取的行数
     */
    private Integer leftCont = 1;

    public TraslationMyMainMyorderJpanel() {

        /**
         * 设置面板
         */
        this.setBounds(0, 27, 760, 460);
        this.setOpaque(false);
        this.setLayout(null);



        /**
         * 组件初始化
         */
        jScrollPane = new JScrollPane();
        chooseLeft = new JLabel("近一周");

        /**
         * 组件透明化
         */
        jScrollPane.setOpaque(false);

        /**
         * 设置组件大小和位置
         */
        jScrollPane.setBounds(8, 63, 750, 372);
        chooseLeft.setBounds(17, 8, 100, 20);

        /**
         * 组件边框透明化
         */
        jScrollPane.setBorder(null);

        /**
         * jScrollPane添加数据
         */
        TraslationTableMyorderUntil.TableModel(jScrollPane, 10);
        jScrollPane.getVerticalScrollBar().setUnitIncrement(50);

        /**
         * 组件设置字体颜色
         */
        chooseLeft.setForeground(Color.white);
        String[] rowDataRight = { "近一周", "近一个月", "一个月前" };
        // 左边面板

        chooseLeftModel = new TraslationSelectOptionJpanel(100, 193, "inkImg/old/1/Z1000.png", rowDataRight);
        chooseLeftModel.setBounds(15, 30, 100, 193);
        chooseLeftModel.setVisible(false);
        add(chooseLeftModel);
        // 左边下拉监听
        this.add(getChooseLeftArrows());
        getChooseLeftArrows().addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                if (leftFlag == 1) {
                    chooseLeftModel.setVisible(true);
                    leftFlag = 0;
                } else {
                    chooseLeftModel.setVisible(false);
                    leftFlag = 1;
                }

            }
        });
        // 左侧列表进行监听
        chooseLeftModel.getJlist().addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub

                int count = chooseLeftModel.getJlist().getSelectedIndex();// 获取你选中的行号（记录）
                String getname = chooseLeftModel.getJlist().getSelectedValue();// 读取你获取行号的某一列的值（也就是字段）
                chooseLeft.setText(getname);
                chooseLeftModel.setVisible(false);
                leftFlag = 1;
                dangqianyeshu = 1;
                /**
                 * 得到选取的行数
                 */
                leftCont = count + 1;

                /**
                 * 传递数据获取我的藏宝阁指定购买中的数据信息 1、获取现在登陆角色的ID 2、初始化SearchOrderBean对象
                 * 3、SearchOrderBean对象获取角色ID 4、SearchOrderBean对象获取订单状态(1未付钱 ，2超时
                 * ， 3已付钱 ，4已取货 ) 5、SearchOrderBean对象获取查询时间(1、一周内 2、一个月内 3、一个月前)
                 * 6、SearchOrderBean对象获取当前页数(点击我的订单按钮页数默认为1)
                 * 7、SearchOrderBean对象转换为对应协议的json对象 8、切换跳转页面编号为11
                 * 9、发送给服务器处理数据信息
                 */

                BigDecimal roleId = RoleData.getRoleData().getLoginResult().getRole_id();

                SearchOrderBean searchOrderBean = new SearchOrderBean();
                searchOrderBean.setTime(leftCont);
                searchOrderBean.setPageNum(dangqianyeshu);
                String sendmes = Agreement.getAgreement().searchMyOrderAgreement(
                        GsonUtil.getGsonUtil().getgson().toJson(searchOrderBean));
                TrslationMainJframe.getTrslationMainJframe().setPanelOpen(11);
                ;
                SendMessageUntil.toServer(sendmes);

            }
        });

        this.add(chooseLeftModel, 10, 1);
        this.add(chooseLeft);

        /**
         * 页码设置
         */
        yema = new JLabel(dangqianyeshu + "/" + zuidayema);
        yema.setBounds(258+91, 442, 58, 17);
        yema.setForeground(UIUtils.COLOR_cbg8);
        yema.setOpaque(false);
        yema.setHorizontalAlignment(SwingConstants.CENTER);
        this.add(yema);

        shouye = new TrslationBtn("inkImg/number/b4/fy1.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, "");
        shouye.setBounds(287, 442, 40, 20);
        this.add(shouye);
        shouye.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                if (dangqianyeshu != 1) {
                    dangqianyeshu = 1;
                    yema.setText(dangqianyeshu + "/" + zuidayema);
                    /**
                     * 传递数据获取我的藏宝阁指定购买中的数据信息 1、获取现在登陆角色的ID
                     * 2、初始化SearchOrderBean对象 3、SearchOrderBean对象获取角色ID
                     * 4、SearchOrderBean对象获取订单状态(1未付钱 ，2超时 ， 3已付钱 ，4已取货 5、所有订单)
                     * 5、SearchOrderBean对象获取查询时间(1、一周内 2、一个月内 3、一个月前)
                     * 6、SearchOrderBean对象获取当前页数(点击我的订单按钮页数默认为1)
                     * 7、SearchOrderBean对象转换为对应协议的json对象 8、切换跳转页面编号为11
                     * 9、发送给服务器处理数据信息
                     */
                    SearchOrderBean searchOrderBean = new SearchOrderBean();
                    searchOrderBean.setTime(leftCont);
                    searchOrderBean.setPageNum(dangqianyeshu);
                    String sendmes = Agreement.getAgreement().searchMyOrderAgreement(
                            GsonUtil.getGsonUtil().getgson().toJson(searchOrderBean));
                    TrslationMainJframe.getTrslationMainJframe().setPanelOpen(11);
                    SendMessageUntil.toServer(sendmes);

                } else {
                    ZhuFrame.getZhuJpanel().addPrompt2("已在首页");
                }
            }
        });

        leftArrows = new TrslationBtn("inkImg/number/b4/fy2.png", 1);
        leftArrows.setBounds(326, 442, 19, 20);
        this.add(leftArrows);
        leftArrows.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                if (dangqianyeshu > 1) {
                    dangqianyeshu--;
                    yema.setText(dangqianyeshu + "/" + zuidayema);
                    /**
                     * 传递数据获取我的藏宝阁指定购买中的数据信息 1、获取现在登陆角色的ID
                     * 2、初始化SearchOrderBean对象 3、SearchOrderBean对象获取角色ID
                     * 4、SearchOrderBean对象获取订单状态(1未付钱 ，2超时 ， 3已付钱 ，4已取货 5、所有订单)
                     * 5、SearchOrderBean对象获取查询时间(1、一周内 2、一个月内 3、一个月前)
                     * 6、SearchOrderBean对象获取当前页数(点击我的订单按钮页数默认为1)
                     * 7、SearchOrderBean对象转换为对应协议的json对象 8、切换跳转页面编号为11
                     * 9、发送给服务器处理数据信息
                     */
                    SearchOrderBean searchOrderBean = new SearchOrderBean();
                    searchOrderBean.setTime(leftCont);
                    searchOrderBean.setPageNum(dangqianyeshu);
                    String sendmes = Agreement.getAgreement().searchMyOrderAgreement(
                            GsonUtil.getGsonUtil().getgson().toJson(searchOrderBean));
                    TrslationMainJframe.getTrslationMainJframe().setPanelOpen(11);
                    SendMessageUntil.toServer(sendmes);
                } else {
                    ZhuFrame.getZhuJpanel().addPrompt2("已经没有上一页了");
                }
            }
        });

        moye = new TrslationBtn("inkImg/number/b4/fy4.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, "");
        moye.setBounds(433, 442, 40, 20);
        this.add(moye);

        moye.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                if (dangqianyeshu != zuidayema) {
                    dangqianyeshu = zuidayema;
                    yema.setText(dangqianyeshu + "/" + zuidayema);
                    /**
                     * 传递数据获取我的藏宝阁指定购买中的数据信息 1、获取现在登陆角色的ID
                     * 2、初始化SearchOrderBean对象 3、SearchOrderBean对象获取角色ID
                     * 4、SearchOrderBean对象获取订单状态(1未付钱 ，2超时 ， 3已付钱 ，4已取货 5、所有订单)
                     * 5、SearchOrderBean对象获取查询时间(1、一周内 2、一个月内 3、一个月前)
                     * 6、SearchOrderBean对象获取当前页数(点击我的订单按钮页数默认为1)
                     * 7、SearchOrderBean对象转换为对应协议的json对象 8、切换跳转页面编号为11
                     * 9、发送给服务器处理数据信息
                     */
                    SearchOrderBean searchOrderBean = new SearchOrderBean();
                    searchOrderBean.setTime(leftCont);
                    searchOrderBean.setPageNum(dangqianyeshu);
                    String sendmes = Agreement.getAgreement().searchMyOrderAgreement(
                            GsonUtil.getGsonUtil().getgson().toJson(searchOrderBean));
                    TrslationMainJframe.getTrslationMainJframe().setPanelOpen(11);
                    SendMessageUntil.toServer(sendmes);

                } else {
                    ZhuFrame.getZhuJpanel().addPrompt2("已在末页");
                }
            }
        });

        rightArrows = new TrslationBtn("inkImg/number/b4/fy3.png", 1);
        rightArrows.setBounds(411, 442, 19, 20);
        this.add(rightArrows);
        rightArrows.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub

                if (dangqianyeshu < zuidayema) {
                    dangqianyeshu++;
                    yema.setText(dangqianyeshu + "/" + zuidayema);
                    /**
                     * 传递数据获取我的藏宝阁指定购买中的数据信息 1、获取现在登陆角色的ID
                     * 2、初始化SearchOrderBean对象 3、SearchOrderBean对象获取角色ID
                     * 4、SearchOrderBean对象获取订单状态(1未付钱 ，2超时 ， 3已付钱 ，4已取货 5、所有订单)
                     * 5、SearchOrderBean对象获取查询时间(1、一周内 2、一个月内 3、一个月前)
                     * 6、SearchOrderBean对象获取当前页数(点击我的订单按钮页数默认为1)
                     * 7、SearchOrderBean对象转换为对应协议的json对象 8、切换跳转页面编号为11
                     * 9、发送给服务器处理数据信息
                     */
                    SearchOrderBean searchOrderBean = new SearchOrderBean();
                    // searchOrderBean.setRole_id(roleId);
                    // searchOrderBean.setStatus(setOrder(chooseLeft.getText()));
                    searchOrderBean.setTime(leftCont);
                    searchOrderBean.setPageNum(dangqianyeshu);
                    String sendmes = Agreement.getAgreement().searchMyOrderAgreement(
                            GsonUtil.getGsonUtil().getgson().toJson(searchOrderBean));
                    TrslationMainJframe.getTrslationMainJframe().setPanelOpen(11);
                    SendMessageUntil.toServer(sendmes);
                } else {
                    ZhuFrame.getZhuJpanel().addPrompt2("已经没有下一页了");
                }
            }
        });

        this.add(jScrollPane, 10, -1);
    }

    private ImageIcon icon1;

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        if (icon1 == null) {
            icon1 = new ImageIcon("inkImg/number/b4/wpxq.png");
        }
        g.drawImage(icon1.getImage(), 0, 5, 760, 55, this);


    }

    /**
     * 刷新页面的页码
     *
//     * @param dangqianyema
     * @param zuidayema
     *
     */
    public void setPage(int zuidayema) {
        this.zuidayema = zuidayema;
        yema.setText(this.dangqianyeshu + "/" + this.zuidayema);
    }

    // (1未付钱 ，2超时 ， 3已付钱 ，4已取货 5、所有订单)
    public Integer setOrder(String leftCont) {
        Integer type = null;
        switch (leftCont) {
            case "全部订单":
                return type;
            case "待付款":
                type = 1;
                break;
            case "已付款":
                type = 3;
                break;
            case "失效":
                type = 2;
                break;
            default:
                break;
        }
        return type;
    }

    public JLabel getChooseLeft() {
        return chooseLeft;
    }

    public void setChooseLeft(JLabel chooseLeft) {
        this.chooseLeft = chooseLeft;
    }

    public JLabel getYema() {
        return yema;
    }

    public void setYema(JLabel yema) {
        this.yema = yema;
    }

    public TraslationSelectOptionJpanel getChooseLeftModel() {
        return chooseLeftModel;
    }

    public void setChooseLeftModel(TraslationSelectOptionJpanel chooseLeftModel) {
        this.chooseLeftModel = chooseLeftModel;
    }

    public int getLeftFlag() {
        return leftFlag;
    }

    public void setLeftFlag(int leftFlag) {
        this.leftFlag = leftFlag;
    }

    public JScrollPane getjScrollPane() {
        return jScrollPane;
    }

    public void setjScrollPane(JScrollPane jScrollPane) {
        this.jScrollPane = jScrollPane;
    }

    public int getDangqianyeshu() {
        return dangqianyeshu;
    }

    public void setDangqianyeshu(int dangqianyeshu) {
        this.dangqianyeshu = dangqianyeshu;
    }

    public int getZuidayema() {
        return zuidayema;
    }

    public void setZuidayema(int zuidayema) {
        this.zuidayema = zuidayema;
    }

    public Integer getLeftCont() {
        return leftCont;
    }

    public void setLeftCont(Integer leftCont) {
        this.leftCont = leftCont;
    }

    public TrslationBtn getShouye() {
        return shouye;
    }

    public void setShouye(TrslationBtn shouye) {
        this.shouye = shouye;
    }

    public TrslationBtn getMoye() {
        return moye;
    }

    public void setMoye(TrslationBtn moye) {
        this.moye = moye;
    }

    public TrslationBtn getLeftArrows() {
        return leftArrows;
    }

    public void setLeftArrows(TrslationBtn leftArrows) {
        this.leftArrows = leftArrows;
    }

    public TrslationBtn getRightArrows() {
        return rightArrows;
    }

    public void setRightArrows(TrslationBtn rightArrows) {
        this.rightArrows = rightArrows;
    }

    public TrslationBtn getChooseLeftArrows() {
        if (chooseLeftArrows == null) {
            chooseLeftArrows = new TrslationBtn("inkImg/number/b4/xlaj.png", 1);
            chooseLeftArrows.setBounds(99, 13, 13, 13);
            chooseLeftArrows.setOpaque(false);
        }
        return chooseLeftArrows;
    }

    public void setChooseLeftArrows(TrslationBtn chooseLeftArrows) {
        this.chooseLeftArrows = chooseLeftArrows;
    }

    public ImageIcon getIcon1() {
        return icon1;
    }

    public void setIcon1(ImageIcon icon1) {
        this.icon1 = icon1;
    }

}
